<?php defined('InShopNC') or exit('Access Invalid!');?>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/common_select.js"></script>
<div class="page">
  <!-- 页面导航 -->
  <div class="fixed-bar">
    <div class="item-title">
      <h3>物流自提服务站管理</h3>
      <ul class="tab-base">
        <li><a href="<?php echo urlAdmin('delivery', 'index');?>"><span><?php echo $lang['nc_manage'];?></span></a></li>
        <li><a href="<?php echo urlAdmin('delivery', 'index', array('sign' => 'verify'));?>"><span>等待审核</span></a></li>
        <li><a href="javascript:void(0);" class="current"><span>设置</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="setting_form" method="post" action="<?php echo urlAdmin('delivery', 'save_setting');?>">
    <input type="hidden" id="form_submit" name="form_submit" value="ok" />
    <input type="hidden" id="province_id_input" name="province_id_input" value="<?php  echo $output['list_setting']['delivery_province_id'] ?>" />
    <input type="hidden" id="city_id_input" name="city_id_input" value="<?php  echo $output['list_setting']['delivery_city_id'] ?>" />
    <input type="hidden" id="area_id_input" name="area_id_input" value="<?php  echo $output['list_setting']['delivery_area_id'] ?>" />
    <table class="table tb-type2">
      <tbody>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="promotion_booth_price">物流自提服务站是否开启<?php echo $lang['nc_colon'];?></label></td>
        </tr>
        <tr class="noborder">
        <td class="vatop rowform onoff"><label for="site_status1" class="cb-enable <?php if($output['list_setting']['delivery_isuse'] == '1'){ ?>selected<?php } ?>" ><span>开启</span></label>
            <label for="site_status0" class="cb-disable <?php if($output['list_setting']['delivery_isuse'] == '0'){ ?>selected<?php } ?>" ><span>关闭</span></label>
            <input id="site_status1" name="delivery_isuse" <?php if($output['list_setting']['delivery_isuse'] == '1'){ ?>checked="checked"<?php } ?>  value="1" type="radio">
            <input id="site_status0" name="delivery_isuse" <?php if($output['list_setting']['delivery_isuse'] == '0'){ ?>checked="checked"<?php } ?> value="<?php echo $output['dlyp_info']['dlyp_state'];?>" type="radio"></td>
          <td class="vatop tips"></td>
        </tr>
        <tr class="noborder">
          <td colspan="2">现在去设置物流自提服务站使用的快递公司，<a onclick="window.parent.openItem('index,express,setting');" href="JavaScript:void(0);">快递公司</a></td>
        </tr>
        <tr class="noborder">
          <td colspan="2" class="required"><label for="promotion_booth_price">物流自提服务站地址<?php echo $lang['nc_colon'];?></label></td>
        </tr>
        <tr class="noborder">
        <td>
            <p id="region">
                <select class="d_inline" name="province_id" id="province_id">
                </select>
            </p>
        </tr>
        <tr class="noborder">
        <td>
            <input id="address" name="address" class="text" type="text" value="<?php  echo $output['list_setting']['delivery_address'] ?>" placeholder="详细街道地址">
        </tr>
      </tbody>
      <tfoot>
        <tr class="tfoot">
          <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>
<script>
$(function(){
    $("#submitBtn").click(function(){
        $("#setting_form").submit();
    });

    // 商品所在地
    var area_select = $("#province_id");
    getArea(function(){
		if(typeof(area_select) == 'object' && nc_a[0].length > 0){
			var areas = new Array();
			areas = nc_a[0];
			$(area_select).append("<option>-请选择-</option>");
			for (i = 0; i <areas.length; i++){
				$(area_select).append("<option value='" + areas[i][0] + "'>" + areas[i][1] + "</option>");
			}
		}
		var province_id = $("#province_id_input").val();
	    if(province_id) {
	        $("#province_id").val(province_id);
	        var text = $("#province_id").find("option:selected").text();

	        var city_id = $("#city_id_input").val();
	        if(city_id) {
	            if(typeof(nc_a[province_id]) != 'undefined'){//数组存在
                    var areas = new Array();
                    var option = "";
                    areas = nc_a[province_id];
                    var EP = new Array();
                    EP[1]= true;EP[2]= true;EP[9]= true;EP[22]= true;EP[34]= true;EP[35]= true;
                    if (typeof(EP[city_id]) == 'undefined'){
                        option = "<option value='0'>"+text+"(*)</option>";
                    }
                    $("<select name='city_id' id='city_id'>"+option+"</select>").insertAfter($("#province_id"));
                    for (var i = 0; i <areas.length; i++){
                    	$("#province_id").next("select").append("<option value='" + areas[i][0] + "'>" + areas[i][1] + "</option>");
                    }
                    $("#city_id").val(city_id);
                    text = $("#province_id").find("option:selected").text();

                    var area_id = $("#area_id_input").val();
    		        if(area_id) {
    		            if(typeof(nc_a[city_id]) != 'undefined'){//数组存在
    	                    var areas = new Array();
    	                    var option = "";
    	                    areas = nc_a[city_id];
    	                    var EP = new Array();
    	                    EP[1]= true;EP[2]= true;EP[9]= true;EP[22]= true;EP[34]= true;EP[35]= true;
    	                    if (typeof(EP[area_id]) == 'undefined'){
    	                        option = "<option value='0'>"+text+"(*)</option>";
    	                    }
    	                    $("<select name='area_id' id='area_id'>"+option+"</select>").insertAfter($("#city_id"));
    	                    for (var i = 0; i <areas.length; i++){
    	                    	$("#city_id").next("select").append("<option value='" + areas[i][0] + "'>" + areas[i][1] + "</option>");
    	                    }
    	                    $("#area_id").val(area_id);
    	                }
    		        }
                }
	        }
	    }
	});
    
    $("#province_id").change(function (){
        // 删除后面的select
        $(this).nextAll("select").remove();
        if (this.value > 0){
            var text = $(this).get(0).options[$(this).get(0).selectedIndex].text;
            var area_id = this.value;
            var EP = new Array();
            EP[1]= true;EP[2]= true;EP[9]= true;EP[22]= true;EP[34]= true;EP[35]= true;
            if(typeof(nc_a[area_id]) != 'undefined'){//数组存在
                var areas = new Array();
                var option = "";
                areas = nc_a[area_id];
                if (typeof(EP[area_id]) == 'undefined'){
                    option = "<option value='0'>"+text+"(*)</option>";
                }
                $("<select name='city_id' id='city_id'>"+option+"</select>").insertAfter(this);
                for (var i = 0; i <areas.length; i++){
                    $(this).next("select").append("<option value='" + areas[i][0] + "'>" + areas[i][1] + "</option>");
                }

                $("#city_id").change(function (){
                    // 删除后面的select
                    $(this).nextAll("select").remove();
                    if (this.value > 0){
                        var text = $(this).get(0).options[$(this).get(0).selectedIndex].text;
                        var area_id = this.value;
                        var EP = new Array();
                        EP[1]= true;EP[2]= true;EP[9]= true;EP[22]= true;EP[34]= true;EP[35]= true;
                        if(typeof(nc_a[area_id]) != 'undefined'){//数组存在
                            var areas = new Array();
                            var option = "";
                            areas = nc_a[area_id];
                            if (typeof(EP[area_id]) == 'undefined'){
                                option = "<option value='0'>"+text+"(*)</option>";
                            }
                            $("<select name='area_id' id='area_id'>"+option+"</select>").insertAfter(this);
                            for (var i = 0; i <areas.length; i++){
                                $(this).next("select").append("<option value='" + areas[i][0] + "'>" + areas[i][1] + "</option>");
                            }

                        }
                    }
                 });
            }
        }
     });
});
</script>